class Page15 extends BaseScreen {
    public constructor() {
        super();
        this.skinName = "resource/eui_skins/Page15Skin.exml";
    }

	private img_1: eui.Image;
    private img_2: eui.Image;
    private img_3: eui.Image;
    private img_4: eui.Image;
	private img_5: eui.Image;
	private scroller_page:eui.Scroller;
	private touch_y:number;
	/**触摸起始位置*/
    private touchStartPos: number;
    private is_move:boolean = false;

    private wait_time:number = 1800;
    private next_wait:number = 0;
    protected childrenCreated(): void {
        super.childrenCreated();
        this.init_view();
        this.resetui();

    }

    public resetui(){
        this.scroller_page.viewport.scrollV = 0;
        this.is_move = false;

        if(this.xx_page){
            this.xx_page.stop();
        }
    }

    public init_view() {
		this.scroller_page.addEventListener(eui.UIEvent.CHANGE_END, this.onChangeEndHandler, this);
		this.scroller_page.addEventListener(eui.UIEvent.CHANGE_START, this.onChangeStartHandler, this);
		this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouchStartHandler, this);
		this.addEventListener(egret.TouchEvent.TOUCH_END, this.onTouchEndHandler, this);
		this.scroller_page.bounces = true;
        this.showPage();
    }

	/**拖动结束*/
    private onChangeEndHandler(evt:UIEvent): void {
        // console.log("ItemScroller >> " + "change end");
   
    }

	/**拖动开始*/
    private onChangeStartHandler(evt:UIEvent) {
		
        // console.log("ItemScroller >> " + "change start");
        this.touchStartPos = this.scroller_page.viewport.scrollV;
		
    }

	private onTouchStartHandler(e:egret.TouchEvent){
		this.touch_y = e.localY;
        this.is_move = false;
	}

	private onTouchEndHandler(e:egret.TouchEvent){
		console.log('end='+e.localY)
        
        this.is_move = true;

		if (this.touchStartPos == -1) { //防点击触发changeend
            return;
        }
        var dict: number;


		dict = Math.abs(e.localY - this.touch_y);
		console.log('dict='+dict+'this.touchStartPos='+this.touchStartPos);
		console.log('this.scroller_page.viewport.scrollV='+this.scroller_page.viewport.scrollV);
        if (this.scroller_page.viewport.scrollV <=0 && dict > 90) {
            // this.scrollToNext();
			console.log('upppp');
			utils.ScreenManager.instance.main_screen.myscrollView.scrollToItem(13,true);
		} else if (this.scroller_page.viewport.scrollV >= (2643-this.height) && dict > 90) {
            // this.scrollToLast();
			console.log('downnnnn');
			utils.ScreenManager.instance.main_screen.myscrollView.scrollToItem(15,true);
        }
        else {
            // this.scrollToItem(this.curItemCount);
			console.log('currrrr');
        }
        this.touchStartPos = -1;
	}

    public showPage() {
        super.showPage();
        this.resetui();

       this.is_move = true;
       this.next_wait = egret.getTimer();
        // this.scroller_page.viewport.scrollV = 500;

        if(this.xx_page){
            this.xx_page.start();
        }
    }

    public resize(): void {
         super.resize();

		 this.scroller_page.height = this.height;
    }

	protected process(){
        if(this.is_move){

            var cha_time:number = egret.getTimer() - this.next_wait;
            if(cha_time >this.wait_time){
                
                if (this.scroller_page.viewport.scrollV >= (2643-this.height)){
                    this.is_move = false;
                }
                this.scroller_page.viewport.scrollV+=5;
            }
            
        }
    }
}